package com.example.rabbitmqtest01.controller;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

@RestController
public class SendMessageController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private RabbitTemplate.ConfirmCallback confirmCallback;
    @PostConstruct
    public void init(){
        rabbitTemplate.setConfirmCallback(confirmCallback);
    }
    @RequestMapping("/send")
    public String sendMessage(){
        CorrelationData correlationData=new CorrelationData();
        correlationData.setId("fanout_id1");
        rabbitTemplate.convertAndSend("fanout_exchange","","heihei",correlationData);
        return "success";
    }
}
